<?php

/* @var $this yii\web\View */
use yii\helpers\Html;
use common\helpers\TStringHelper;

$this->title = Yii::t('frontend', 'home');

$month = (int)date('m');
?>
<?=Html::cssFile("/static/frontend/css/huizhan.css")?>
<?=Html::jsFile('/static/frontend/js/swipe.js')?>
<div class="home">
    <!-- header-banner -->
    <div class="headBanner">
        <div class="bannerBox">
            <?php
            if (!empty($banner)) {
                if (count($banner) > 1) {
            ?>
            <div class="swipe" id='slider'>
                <div class="swipe-wrap">
                    <?php
                        foreach ($banner as $value) {
                            if ($value['type'] == \common\models\Banner::BANNER_TYPE_VIDEO) {
                    ?>
                    <div>
                        <video width="1680" height="835" controls style="max-width: 100%;">
                            <source src="<?=$value['file']?>" type="video/mp4">
                        </video>
                    </div>
                    <?php
                            }else{
                    ?>
                    <div class="text-center img"><a href="<?=!empty($value['url'])?$value['value']:'javascript:;'?>"><img src="<?=$value['file']?>" alt="<?=$value['title']?>" /></a></div>
                    <?php
                            }
                        }
                    ?>
                </div>
            </div>
            <div class="clearfix"></div>
            <script>
                var slider = Swipe(document.getElementById('slider'), {
                    auto: 3000,
                    continuous: true
                });
            </script>
            <?php
                }else{
                    $content = $banner[0];
                    if ($content['type'] == \common\models\Banner::BANNER_TYPE_VIDEO) {
                ?>
                <div class="text-center">
                    <video width="1680" height="835" controls style="max-width: 100%;">
                        <source src="<?=$content['file']?>" type="video/mp4">
                    </video>
                </div>
                <?php
                    }else{
                ?>
                 <div class="text-center img"><a href="<?=!empty($content['url'])?$content['url']:'javascript:;'?>"><img src="<?=$content['file']?>" alt="<?=$content['title']?>" /></a></div>
                <?php
                    }
                }
            }else{
            ?>
            <div class="text-center"><img src="<?=\yii\helpers\Html::img('/static/frontend/image/banner.jpg')?>" alt="" /></div>
            <?php
            }
            ?>
        </div>

        <div class="headBanner_mark flex f_center">
            <div class="headBanner_mark_min">
                <div class="larg_logo img"><img src="<?=Yii::$app->system->getLogo()?>" alt="<?=Yii::$app->system->title()?>" /></div>
                <p class="flex"><span><?=Yii::$app->system->getLogoText()?></span></p>
                <form action="<?=Yii::$app->urlManager->createUrl(['zhanhui/index'])?>" method="get" id="index_form">
                    <div class="headBanner_mark_min_search">
                        <input type="text" name="keywords" class="index_keywords" placeholder="<?=Yii::$app->system->getSearchText()?>"/>
                        <span class="index_search"><i class="iconfont">&#xe643;</i></span>
                    </div>
                </form>
                <script>
                    $(function () {
                        $(".index_search").on('click', function () {
                            $("#index_form").submit();
                        })
                        $(".index_keywords").keypress(function (e) {
                            if (e.keyCode == 13) {
                                $("#index_form").submit();
                            }
                        })
                    })
                </script>
            </div>
        </div>
        <div class="headBanner_foot">
            <div class="contBox headBanner_foot_min">
                <div class="head_mark_min flex">
                    <div class="head_mark_min_block">
                        <p class="head_mark_block_title flex"><i class="iconfont">&#xe620;</i>热门城市：</p>
                        <?php
                        if (!empty($regionHot)) {
                        ?>
                        <div class="swipe" id="slider2">
                            <div class="swipe-wrap">
                            <ol class="fbox swipe-ol">
                            <?php
                            $i = 1;
                                foreach ($regionHot as $val) {
                                    $city_arr = array(
                                        array(
                                            'id' => $val['id'],
                                            'name' => $val['name'],
                                        )
                                    );
                                    $city_arr = urlencode(urlencode(json_encode($city_arr)));
                            ?>
                            <li class="fl t_o"><a href="<?= Yii::$app->urlManager->createUrl(['zhanhui/index', 'city_arr' => $city_arr, 'city' => $val['name']]) ?>" title="<?= $val['name'] ?>"><?= $val['name'] ?></a></li>
                            <?php
                                if ($i > 1 && $i%18==0 && $i<count($regionHot)){
                            ?>
                            </ol><ol class="fbox swipe-ol">
                            <?php
                                }
                                $i++;
                            }
                            ?>
                            </ol>
                            </div>
                        </div>
                        <?php
                        }
                        if (count($regionHot) > 18) {
                        ?>
                        <span><i class="iconfont region-prev">&#xe65d;</i><i class="iconfont can_sle region-next">&#xe617;</i></span>
                        <script>
                            var slider2 = Swipe(document.getElementById('slider2'), {
                                auto: false,
                                continuous: true
                            });
                            $(function(){
                                $(".region-prev").click(function(e){
                                    e.preventDefault();
                                    slider2.prev();
                                });
                                $(".region-next").click(function(e){
                                    e.preventDefault();
                                    slider2.next();
                                });
                            });
                        </script>
                        <?php
                        }
                        //php获取本周周起始时间戳和结束时间戳
                        $thisweek_start=mktime(0,0,0,date('m'),date('d')-date('w'+1),date('Y'));
                        $thisweek_end=mktime(23,59,59,date('m'),date('d')-date('w')+7,date('Y'));
                        //php获取本月起始时间戳和结束时间戳
                        $thismonth_start=mktime(0,0,0,date('m'),1,date('Y'));
                        $thismonth_end=mktime(23,59,59,date('m'),date('t'),date('Y'));
                        //近三月
                        $threemonth_start=date('Y-m-01' ,strtotime('-2 month'));
                        $threemonth_end=date('Y-m-d');
                        ?>
                    </div>
                    <div class="head_mark_min_block">
                        <p class="head_mark_block_title flex"><i class="iconfont">&#xe615;</i>展会时间：</p>
                        <ol class="fbox">
                            <li class="fl t_o"><a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/index', 'starttime' => date('Y-m-d', $thisweek_start), 'endtime' => date('Y-m-d', $thisweek_end)])?>">本周</a></li>
                            <li class="fl t_o"><a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/index', 'starttime' => date('Y-m-d', $thismonth_start), 'endtime' => date('Y-m-d', $thismonth_end)])?>">本月</a></li>
                            <li class="fl t_o"><a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/index', 'starttime' => $threemonth_start, 'endtime' => $threemonth_end])?>">近三月</a></li>
                        </ol>
                        <ol class="fbox">
                            <?php
                            $exhibitionService = new \common\services\ExhibitionServices();
                            for ($i = 1; $i <= 12; $i++) {
                                $monthCount = $exhibitionService->getMonthCount($i);
                            ?>
                            <li class="fl t_o <?=$monthCount>0?'':'none'?>"><a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/index', 'starttime' => TStringHelper::monthStart($i), 'endtime' => TStringHelper::monthEnd($i)])?>" class="<?=date('m')==$i?'active':''?>"><?=sprintf("%01d", $i)?>月</a></li>
                            <?php
                            }
                            ?>
                        </ol>
                    </div>
                    <div class="head_mark_min_block">
                        <p class="head_mark_block_title flex"><i class="iconfont">&#xe65f;</i>行业分类：</p>
                        <div class="swipe" id="slider3">
                            <div class="swipe-wrap">
                            <ol class="fbox category swipe-ol">
                                <?php
                                if (!empty($category)){
                                    $i = 1;
                                    foreach ($category as $v) {
                                ?>
                                <li class="fl t_o"><a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/index', 'category_id' => $v['id'], 'category_name' => $v['name']])?>" title="<?=$v['name']?>"><?=$v['name']?></a></li>
                                <?php
                                if ($i > 1 && $i%9==0 && $i<count($regionHot)){
                                ?>
                            </ol><ol class="fbox category swipe-ol">
                                    <?php
                                    }
                                    $i++;
                                    }
                                }
                                ?>
                            </ol>
                            </div>
                        </div>
                        <span><i class="iconfont category-prev">&#xe65d;</i><i class="iconfont can_sle category-next">&#xe617;</i></span>
                        <script>
                            var slider3 = Swipe(document.getElementById('slider3'), {
                                auto: false,
                                continuous: true
                            });
                            $(function(){
                                $(".category-prev").click(function(e){
                                    e.preventDefault();
                                    slider3.prev();
                                });
                                $(".category-next").click(function(e){
                                    e.preventDefault();
                                    slider3.next();
                                });
                            });
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="recommend-bg clearfix">
        <!--正文一标题-->
        <div class="min_contBox">
            <div class="minBlock_title_box">
                <p class="minBlock_title">行业展会</p>
            </div>
            <p class="minBlock_tambl_nav t_center"><?=Yii::$app->system->getValueByCode('index-exhibition-text')?></p>
            <div class="recomend_tab flex f_center">
                <a href="javascript:;" data-id="" class="sel exhibition-list">全部</a>
                <?php
                if (!empty($recommendCategory)) {
                    foreach ($recommendCategory as $v) {
                ?>
                <a class=" exhibition-list" href="<?=Yii::$app->urlManager->createUrl(['home/get-list', 'category_id' => $v['id'], 'category_name' => $v['name']])?>" data-id="<?=$v['id']?>"><?=$v['name']?></a>
                <?php
                    }
                }
                ?>
                <a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/index'])?>" class="more">查看更多<i></i></a>
            </div>
        </div>
        <!--推荐列表-->
        <div class="recomendBox" id="recommend-zhanhui">
            <div class="load-wrapp" style="display: none;"><div class="load-9"><div class="spinner"><div class="bubble-1"></div><div class="bubble-2"></div></div></div></div>
            <!-- //ajax -->
        </div>
    </div>
    <script>
        $(function () {
            $(".exhibition-list").on('click', function (e) {
                e.preventDefault();
                if ($(this).hasClass('sel')) {
                    return ;
                }
                $(".exhibition-list").removeClass('sel');
                $(this).addClass('sel');
                var categoryId = $(this).data('id');
                $("#recommend-zhanhui").find(".ajax-recommend").addClass('hidden');
                if ($("#index_recommend_"+categoryId).length > 0) {
                    $("#index_recommend_"+categoryId).removeClass('hidden');
                    return false;
                }
                getRecommendZhanHui(categoryId);
            })
        })
        function getRecommendZhanHui(categoryId){
            $("#recommend-zhanhui").find(".load-wrapp").show();
            $.ajax({
                url: '<?=Yii::$app->urlManager->createUrl(['home/get-list'])?>',
                data: {categoryId: categoryId},
                type: 'GET',
                dataType: 'html',
                // async: false,
                success: function (response) {
                    $("#recommend-zhanhui").find(".load-wrapp").hide();
                    $("#recommend-zhanhui").append(response);
                    $("#index_recommend_"+categoryId).removeClass('hidden');
                },
                error: function (error) {
                    $("#recommend-zhanhui").find(".load-wrapp").hide();
                    alert(JSON.stringify(error));
                    return false;
                }
            })
        }
        getRecommendZhanHui('');
    </script>

    <div class="text-center img"><?=\frontend\widgets\Ad::widget(['position' => 'index_ad_1'])?></div>
    <div class="recommend_hall_bg">
        <div class="recommend_hall">
            <!--正文二标题-->
            <div class="min_contBox">
                <div class="minBlock_title_box">
                    <p class="minBlock_title">展馆</p>
                </div>
                <p class="minBlock_tambl_nav t_center">
                    <?=Yii::$app->system->getValueByCode('index-hall-txt')?>
                </p>
                <div class="recomend_tab flex f_center">
                    <span class="recommend-txt t_red get-hall" data-id="">推荐</span>
                    <?php
                    if (!empty($regionRecommend)) {
                    ?>
                    <div class="swipe" style="width: 525px;" id="slider6">
                        <div class="swipe-wrap clearfix">
                            <ol class="recomend_tab_list fbox swipe-ol">
                                <?php
                                $i = 1;
                                foreach ($regionRecommend as $val) {
                                ?>
                                <li><a class="get-hall" href="javascript:;" data-id="<?=$val['id']?>"><?=$val['name']?></a></li>
                                <?php
                                    if ($i%9==0 && $i < count($regionRecommend)) {
                                ?>
                                </ol><ol class="recomend_tab_list fbox swipe-ol">
                                <?php
                                    }
                                    $i ++;
                                }
                                ?>
                            </ol>
                        </div>
                    </div>
                    <div class="check_page flex">
                        <?php
                        if ($i > 9) {
                        ?>
                        <i class="iconfont recommend-city-prev">&#xe65d;</i>
                        <?php
                        }
                        ?>
                        <div class="clearfix" id="index-recommend-city">
                            <?php
                            $j = 1;
                            foreach ($regionRecommend as $key => $val) {
                                if ($j%9==0 && $j < count($regionRecommend)) {
                            ?>
                            <span class="<?=$key==0?'on':''?>"></span>
                            <?php
                                }
                                $j ++;
                            }
                            ?>
                        </div>
                        <?php
                        if ($i > 9) {
                        ?>
                        <i class="iconfont recommend-city-next">&#xe617;</i>
                        <?php
                        }
                        ?>
                    </div>
                    <script>
                        /*推荐城市展馆*/
                        var slider6 = Swipe(document.getElementById('slider6'), {
                            auto: 3000,
                            continuous: true,
                            callback: function(pos) {
                                var i = bullets6.length;
                                while (i--) {
                                    bullets6[i].className = ' ';
                                }
                                bullets6[pos].className = 'on';
                            }
                        });
                        var bullets6 = document.getElementById('index-recommend-city').getElementsByTagName('li');
                        $(function(){
                            $(".recommend-city-prev").click(function(e){
                                e.preventDefault();
                                slider6.prev();
                            });
                            $(".recommend-city-next").click(function(e){
                                e.preventDefault();
                                slider6.next();
                            });
                        });
                    </script>
                    <?php
                    }
                    ?>
                </div>
            </div>
            <div class="Mosaic_are">
                <div class="tab-content" id="hall_box">
                    <div class="load-wrapp"><div class="load-9"><div class="spinner"><div class="bubble-1"></div><div class="bubble-2"></div></div></div></div>
                </div>
            </div>
            <script>
                $(function () {
                    $(".get-hall").on('click', function (e) {
                        e.preventDefault();
                        if ($(this).hasClass('t_red')) {
                            return ;
                        }
                        $(".get-hall").removeClass('t_red');
                        $(this).addClass('t_red');
                        var region_id = $(this).data('id');
                        indexGetHall(region_id);
                    })
                })
                function indexGetHall(region_id) {
                    $(".index_hall").addClass('hidden');
                    $(".load-wrapp").show();
                    if ($("#region_"+region_id).length > 0 ) {
                        $(".load-wrapp").hide();
                        $("#region_"+region_id).removeClass('hidden');
                    }else {
                        $.ajax({
                            url: '<?=Yii::$app->urlManager->createUrl(['home/get-hall'])?>',
                            data: {region_id: region_id},
                            type: 'GET',
                            dataType: 'html',
                            //async: false,
                            success: function (response) {
                                setTimeout(function() {
                                    $(".load-wrapp").hide();
                                    $("#hall_box").append(response);
                                }, 2000);
                            },
                            error: function (error) {
                                $(".load-wrapp").hide();
                                alert(JSON.stringify(error));
                                return false;
                            }
                        })
                    }
                }
                indexGetHall('');
            </script>
        </div>
    </div>
    <!--底部推荐区域-->
    <div class="foot_recomend">
        <div class="flex f_between f_relative">
            <div class="foot_recomend_block_left">
                <div class="foot_recomend_title flex f_between f_relative">
                    <ul class="fbox index_switch">
                        <li class="fl act" data-type="recommend"><a href="javascript:;">推荐展会</a></li>
                        <li class="fl" data-type="near"><a href="javascript:;">近期展会</a></li>
                    </ul>
                </div>
                <div class="foot_recomend_list_box clearfix">
                    <div class="index_switch_content index_recommend f_relative clearfix">
                    <?php
                    if (!empty($recommend)) {
                    ?>
                    <div class="swipe" id="slider4">
                        <div class=" swipe-wrap">
                            <div class="pull-left">
                            <ul class="foot_recomend_list flex f_warp">
                                <?php
                                $i = 1;
                                foreach ($recommend as $val) {
                                ?>
                                <li class="<?=$i%2==1?'left':'right'?>">
                                    <div>
                                        <div class="recomedBox_item_img_box">
                                            <a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/detail', 'id' => $val['id']])?>" target="_blank" title="<?=$val['title']?>"><img src="<?=$val['litpic']?>" alt="<?=$val['title']?>" /></a>
                                            <a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/index', 'category_id' => $val['category_id'], 'category_name' => $val['category_name']])?>" class="category-tag btn_red" target="_blank"><?=$val['category_name']?></a>
                                        </div>
                                        <div class="recomedBox_item_min">
                                            <p class="t_o_lin recomedBox_item_min_title"><a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/detail', 'id' => $val['id']])?>" target="_blank" title="<?=$val['title']?>"><?=$val['title']?></a></p>
                                            <p class="recomedBox_item_min_info flex f_between">
                                                <span class="t_o"><?=Yii::t('frontend', 'exhibition_time')?>：<?=$val['show_start']?><i><?=Yii::t('frontend', 'to')?></i><?=$val['show_end']?></span>
                                                <span class="t_o"><?=Yii::t('frontend', 'place')?>：<?=$val['city']?></span>
                                            </p>
                                        </div>
                                    </div>
                                </li>
                                <?php
                                    if ($i%2 == 0 && $i < count($recommend)) {
                                ?>
                                </ul>
                            <?php
                            if ($i%4 == 0) {
                            ?>
                            </div><div class="pull-left">
                            <?php
                            }
                            ?>
                                <ul class="foot_recomend_list flex f_warp">
                                <?php
                                    }
                                    $i++;
                                }
                                ?>
                            </ul>
                            </div>
                        </div>
                    </div>
                    <ol class="fbox" id="index-recommend-page">
                        <?php
                        foreach ($recommend as $key => $val) {
                            if ($key%4==3) {
                        ?>
                        <li class="fl <?= $key == 3 ? 'on' : '' ?>"></li>
                        <?php
                            }
                        }
                        ?>
                    </ol>
                    <script>
                        /*推荐展会*/
                        var slider4 = Swipe(document.getElementById('slider4'), {
                            auto: 3000,
                            continuous: true,
                            callback: function(pos) {
                                var i = bullets4.length;
                                while (i--) {
                                    bullets4[i].className = ' ';
                                }
                                bullets4[pos].className = 'on';
                            }
                        });
                        var bullets4 = document.getElementById('index-recommend-page').getElementsByTagName('li');
                    </script>
                    <?php
                    }
                    ?>
                    </div>
                    <div class="index_switch_content index_near f_relative clearfix" style="display: none">
                    <?php
                    if (!empty($near)) {
                    ?>
                    <div class="swipe" id="slider5">
                        <div class=" swipe-wrap">
                            <div class="pull-left">
                    <ul class="foot_recomend_list flex f_warp">
                        <?php
                        $i = 1;
                        foreach ($near as $val) {
                        ?>
                        <li class="<?=$i%2==1?'left':'right'?>">
                            <div>
                                <div class="recomedBox_item_img_box">
                                    <a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/detail', 'id' => $val['id']])?>" target="_blank" title="<?=$val['title']?>"><img src="<?=$val['litpic']?>" alt="<?=$val['title']?>" /></a>
                                    <a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/index', 'category_id' => $val['category_id'], 'category_name' => $val['category_name']])?>" class="category-tag btn_red" target="_blank"><?=$val['category_name']?></a>
                                </div>
                                <div class="recomedBox_item_min">
                                    <p class="t_o_lin recomedBox_item_min_title"><a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/detail', 'id' => $val['id']])?>" target="_blank" title="<?=$val['title']?>"><?=$val['title']?></a></p>
                                    <p class="recomedBox_item_min_info flex f_between">
                                        <span class="t_o"><?=Yii::t('frontend', 'exhibition_time')?>：<?=$val['show_start']?><i><?=Yii::t('frontend', 'to')?></i><?=$val['show_end']?></span>
                                        <span class="t_o"><?=Yii::t('frontend', 'place')?>：<?=$val['city']?></span>
                                    </p>
                                </div>
                            </div>
                        </li>
                        <?php
                            if ($i%2 == 0 && $i < count($near)) {
                        ?>
                        </ul>
                    <?php
                    if ($i%4 == 0) {
                    ?>
                    </div><div class="pull-left">
                    <?php
                    }
                    ?>
                        <ul class="foot_recomend_list flex f_warp">
                        <?php
                            }
                            $i++;
                        }
                        ?>
                    </ul>
                            </div>
                        </div>
                    </div>
                    <ol class="fbox" id="index-near-page">
                        <?php
                        foreach ($near as $key => $val) {
                            if ($key%4==3) {
                                ?>
                                <li class="fl <?= $key == 3 ? 'on' : '' ?>"></li>
                                <?php
                            }
                        }
                        ?>
                    </ol>
                    <?php
                    }
                    ?>
                    </div>
                </div>
                <script>
                    var k = 1;
                    $(".index_switch > li").on('click', function(e){
                        if ($(this).hasClass('act')) {
                            return false;
                        }
                        $(this).siblings("li").removeClass('act');
                        $(this).addClass('act');
                        var type = $(this).data('type');
                        $(".index_switch_content").hide();
                        $(".index_"+type).show();
                        if (k == 1 && type == 'near') {
                            var slider5 = Swipe(document.getElementById('slider5'), {
                                auto: 3000,
                                continuous: true,
                                callback: function(pos5) {
                                    var i = bullets5.length;
                                    while (i--) {
                                        bullets5[i].className = ' ';
                                    }
                                    bullets5[pos5].className = 'on';
                                }
                            });
                            var bullets5 = document.getElementById('index-near-page').getElementsByTagName('li');
                        }
                        k ++;
                    })
                </script>
            </div>
            <div class="foot_recomend_block_right">
                <div class="foot_recomend_block_right_box">
                    <div class="foot_recomend_title flex f_between f_relative">
                        <ul class="fbox">
                            <li class="fl act">行业新闻</li>
                        </ul>
                        <a href="<?=Yii::$app->urlManager->createUrl(['news/index', 'categoryId' => 3])?>" class="foot_recomend_title_more">了解更多</a>
                    </div>
                    <div class="foot_recomend_right_list_box">
                        <?php
                        if (!empty($news)){
                        ?>
                        <ul class="foot_recomend_right_list">
                            <?php
                            foreach ($news as $val) {
                            ?>
                            <li>
                                <div class="flex f_between index-news-title">
                                    <a href="<?=Yii::$app->urlManager->createUrl(['news/detail', 'id' => $val['id']])?>" class="t_o"><?=$val['title']?></a>
                                    <i><?=date('Y-m-d', $val['created_at'])?></i>
                                </div>
                                <p class="t_o_lin"><?=$val['desc']?></p>
                            </li>
                            <?php
                            }
                            ?>
                        </ul>
                        <?php
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
